<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page import="com.google.gdata.data.calendar.CalendarEventEntry" %>
<%@page import="java.util.List"%>
<%@page import="ar.edu.itba.bundundu.domain.BundunduEvent"%>
<%@page import="ar.edu.itba.bundundu.CalendarServlet"%>

<% request.setAttribute("tab", 3); %>
<%@ include file="/header.jsp" %>


<%@page import="com.google.gdata.data.calendar.CalendarEntry"%>
<%@page import="com.google.gdata.data.calendar.SelectedProperty"%><style>
/*
 * CSS Calendar
 * Tim Wright
 * Chris Coyier
 -----------------------------*/

*		{margin:0;padding:0;}
body		{font:1em/1.4 Verdana, Arial, Helvetica, sans-serif;
			background: url(http://bundundu.appspot.com/images/bg.jpg) top center no-repeat #545454;}
body *		{display:inline;}
ol.calendar    {width:62em;margin:0 ;display:block; min-height: 200px;
			background: url(http://bundundu.appspot.com/images/tl.png) top left no-repeat; padding: 12px 0 0 20px;}
li		{list-style:none;}
p.link		{text-align:center;display: block;}
h1		{font:1.5em Verdana, Arial, Helvetica, sans-serif;}

/*
 * Day styles
 -------------------------*/
li li		{width:7.5em;height:7.5em;float:left;margin:.2em; padding:.2em;overflow:auto;
			background: url(http://bundundu.appspot.com/images/day-bg.png) bottom right no-repeat; }

/*
 * Day content (UL/OL & P)
 -------------------------*/
li li p	 {font-size:.7em;display:block;}
li li ol	 {width:auto;}
li li ul li,
li li ol li     {font-size:.7em;display:block;height:auto;width:auto; background: none;
			margin:0;padding:.2em 0;float:none;}

/*
 * Holiday class
 -------------------------*/
li li.holiday    {  }

/*
 * Inactive months
 -------------------------*/
li#lastmonth li,
li#nextmonth li    { background: url(http://bundundu.appspot.com/images/day-bg-inactive.png);}

th		{width:7.5em;float:left;margin:.2em; padding:.2em;overflow:auto;}

/***********/
.event{
	-moz-border-radius: 3px;
	color: white;
	visibility: visible;
}

</style>

<script>
<!--
function showEvent(id)
{

	var i=1;
	var event;
	while(event= document.getElementById(id + i)){
		if(event.getStyle('visibility') == 'hidden')
        {
			event.setStyle('visibility', 'visible');
        }
        else
        {
        	event.setStyle('visibility', 'hidden');
        }
        i+=1;
	}
	
}
</script>

<%
	List <BundunduEvent> events=(List<BundunduEvent>)request.getAttribute("events");
	BundunduEvent event;
%>
<c:out value="${err}"/>
</br>
<h1 style="text-align: center;">
<a href='http://apps.facebook.com/bundundu/showcalendars?date=<c:out value="${prev_month}"/>' >Previous</a>
 <c:out value="${month}" /> 
<a href='http://apps.facebook.com/bundundu/showcalendars?date=<c:out value="${next_month}"/>' >Next</a>
</h1>
<ol class="calendar" start="6">

	<table>
			<th>Sunday</th>
			<th>Monday</th>
			<th>Tuesday</th>
			<th>Wednesday</th>
			<th>Thursday</th>
			<th>Friday</th>
			<th>Saturday</th>
	</table>


	<li id="lastmonth">
		<ol start="29">
			<c:forEach var="j" begin="1" end="${first-1}" step="1">
				<li><c:out value="${days_last-first+j+1}" /></li>
			</c:forEach>
		</ol>
	</li>

	<li id="thismonth">
		<ol>
		
		<c:forEach var="count_day" begin="1" end="${days}" step="1" varStatus ="status">
			
			<li>
				<c:out value="${count_day}"/>
				<jsp:useBean id="count_day" type="java.lang.Number" />
				<%
					while((event=CalendarServlet.getEntry(events, count_day.intValue()))!=null)
					{				
						//visibility:hidden
						String visible="";
						if(event.getSelect()==false){
							visible="; visibility:hidden";
						}
						out.println("<div class='event' id='"+ event.getCalendarId()+"'  style='background-color:" + event.getColor() + visible +"'>" + event.getEventEntry().getTitle().getPlainText() + "</div>");
					}
				%>
			</li>
			
		</c:forEach>
			
		</ol>
	</li>


</ol>

<% 
List<CalendarEntry> calendars= (List<CalendarEntry>)request.getAttribute("calendars"); 
int i=0;
%>
<div class="calendars">
	<fieldset title='Calendars'>
		<legend>Calendars:</legend>
		<c:forEach items="${calendars}" var="cal">
			</br>
			<input type='checkbox' <% if(calendars.get(i).getSelected().equals(SelectedProperty.TRUE)){out.println("checked='checked'");}%> onclick='showEvent("<c:out value="${cal.id}"/>");' /> <c:out value="${cal.title.plainText}"/><br/>	
			<% i++; %> 
		</c:forEach>
		</br>
	</fieldset>
</div>
